from python_basic.common.xcommon import sep
from python_basic.exercise.oop.mro.Person import Person
from python_basic.exercise.oop.mro.Student import Student

"""
to-do: add comments
"""


class PersonShoot(Person):

    def __init__(self, name, gun='AK', bullet=0):
        self.set_name(name)
        self.set_province('HK')
        self.__gun = gun
        self.__bullet = bullet

    def __del__(self):
        super().__del__()
        print(f'Destructing PersonShoot {self._Person__name}')

    def __str__(self):
        return super().__str__() \
               + f'\n{{ PersonShoot: gun={self.__gun} bullet(s)={self.__bullet} }}'

    def set_gun(self, gun):
        self.__gun = gun

    def get_gun(self):
        return self.__gun

    def add_bullet(self, n):
        ori = self.__bullet
        self.__bullet += n
        print(f'{self._Person__name} got {n} bullets(s). Original bullet(s): {ori}. Bullet(s) total: {self.__bullet}')

    def shoot(self, n=1):
        if n < 1:
            print('Invalid parameter:', n)
            return
        if self.__bullet < n:
            print(self.get_name(), ' has no more than ', n, ' bullet(s). Cannot shoot!')
            return
        self.__bullet -= n
        print(self.get_name(), ' shot ', n, ' bullet(s). Rest bullet(s): ', self.__bullet, sep='')


if '__main__' == __name__:
    sep(label='xiaoyi')
    xiaoyi = PersonShoot('小一')
    print(xiaoyi)
    xiaoyi.add_bullet(5)
    for i in range(7):
        xiaoyi.shoot(1)
    xiaoyi.add_bullet(10)
    xiaoyi.shoot(100)
    xiaoyi.shoot(7)
    xiaoyi.shoot(0)
    xiaoyi.shoot(-2)
    xiaoyi.shoot(2)
    xiaoyi.shoot(100)
    xiaoyi._PersonShoot__bullet += 200
    xiaoyi.shoot(100)
    print(xiaoyi.__class__)
    print(xiaoyi)
    sep(label='End of testing PersonShoot')
